<template>
  <div v-if="isloading">
    <div v-for="item in props.formSectionList" :key="item.code">
      <div class="contract_base_title">{{ item.title }}</div>
      <zcb-form
        v-if="item.typeCode == 'FORM'"
        :isPreview="props.isPreview.baseInfo"
        :modelValue="formValue.KPI_BASIC"
        :schema="item.formTemplateFieldVOList"
        :options="formOptions"
      >
      </zcb-form>
      <div v-else>
        <el-button type="info" v-if="props.isPreview.examineTable && formValue.vendors.length > 5" link class="more" @click="handelMore(item)"
          >查看更多</el-button
        >
        <row-tableV1
          ref="contactsColumns1Ref"
          :showIndex="false"
          :column="item.formTemplateFieldVOList"
          :tableData="formValue.KPI_VENDOR"
          :showActionBtn="false"
          v-model:selectdList="mutipleValue"
          :pageConfig="''"
        >
          <template #scorePeopleTotal="scope">
            <span style="color: #3487e2" @click="handelScoringProgress(scope.scope)" v-if="Number(scope?.scope?.scorePeopleTotal) > 0">{{
              `${Number(scope.scope.scorePeopleCompleteTotal)}/${Number(scope.scope.scorePeopleTotal)}`
            }}</span>
            <span v-else>--</span>
          </template>
          <template #finalGradeRuleContentName="scope">
            <div>{{ scope.scope.finalGradeRuleContentName || '--' }}</div>
          </template>
          <template #remark="scope">
            <div>{{ scope.scope.remark || '--' }}</div>
          </template>
          <template #targetFileUid="{ scope }">
            <!-- {{ scope.targetFileUidList }} -->
            <zcb-upload
              :fieldSceneVo="{
                moduleCode: fileKeys['moduleCode'],
                sceneCode: fileKeys['sceneCode'],
                fieldTypeCode: fileKeys['fieldTypeCode']
              }"
              :value="scope.targetFileUidList"
              :isExhibition="false"
              :isDownload="true"
              :disabled="true"
              :limit="Number(fileKeys['attachNumberLimit'])"
              :isShowBtn="false"
              upType="table"
              :isTableUpload="true"
              @onComplete="fileChangeHandle(scope.index, $event)"
            >
            </zcb-upload>
          </template>
        </row-tableV1>
        <p class="totalTable">
          共<span>{{ formValue.KPI_VENDOR?.length }}</span
          >条考评数据，涉及<span>{{ formValue.KPI_VENDOR?.length }}</span
          >位供应商
        </p>
      </div>
    </div>
    <select-template
      :isPreview="props.isPreview.selectTemplate"
      :modelValue="formValue.KPI_TMPL"
      :accessType="formValue?.accessType"
      :formOptions="formOptions"
    ></select-template>
    <review-panel :isPreview="props.isPreview.reviewPanel" :modelValue="formValue.KPI_REVIEW_TEAM_DETAIL" :formOptions="formOptions" :vendorList="formValue.KPI_VENDOR"></review-panel>
    <scoring-progress-dialog ref="scoringProgressDialogRef" :mergeFields="mergeFields"></scoring-progress-dialog>
  </div>
</template>
<script setup>
import { ref, watch, onMounted } from 'vue'
import { useI18n } from 'vue-i18n'
import listMixins from '@/hooks/useList'
import { ElMessage } from 'element-plus'
import selectTemplate from './selectTemplate.vue'
import reviewPanel from './reviewPanel.vue'
import scoringProgressDialog from './scoringProgressDialog.vue'
let { formOptions } = listMixins()
const { t } = useI18n()
import { useRoute } from 'vue-router'
const $route = useRoute()
const $emit = defineEmits(['update:modelValue', 'change'])
const props = defineProps({
  modelValue: {
    type: Object,
    default: () => {}
  },
  formSectionList: {
    type: Array,
    default: () => []
  },
  formOptions: {
    type: Object,
    default: () => {}
  },
  isPreview: {
    type: Object,
    default: () => {}
  }
})

const formValue = ref(props.modelValue)
const rateList = ref(formValue.value.rateList || [])
const isloading = ref(false)
const examineTypeCn = new Map([
  ['10', '月度考核'],
  ['20', '季度考核'],
  ['30', '半年度考核'],
  ['40', '年度考核']
])
// console.log(formValue.value)
const fileKeys = ref({
  moduleCode: 'emd',
  sceneCode: 'routine_multifile_1',
  fieldTypeCode: 'FILE_UPLOAD',
  attachNumberLimit: '20'
})
formValue.value.KPI_BASIC.examineTypeCn = examineTypeCn.get(formValue.value.KPI_BASIC.examineType)

const mutipleValue = ref([])
const tableMoreDialogRef = ref()
const tableMoreColumn = ref([])
const code = ref()
const scoringData = ref([]) // 评分进展数据
const mergeFields = ref(['code', 'name', 'inditorWeight', 'scoringCriteria', 'score']) // 合并的列(指标类别、指标名称、指标权重、评分标准、分值、打分方式)
const scoringProgressDialogRef = ref()
console.log(props.formSectionList)
console.log(formValue)
onMounted(() => {
  isloading.value = true

  props.formSectionList.forEach((item) => {
    console.log(item)
    if (item.typeCode == 'LIST') {
      fileKeys.value = item.formTemplateFieldVOList.find((v) => v.fieldCode == 'targetFileUid')
      console.log(fileKeys)
    }
  })
})
// 评分进展
const handelScoringProgress = (data) => {
  scoringData.value = data
  scoringProgressDialogRef.value.showDialog(formValue.value.KPI_BASIC.kpiTaskId, scoringData.value.vendorId)
}

// 查看更多
const handelMore = (data) => {
  tableMoreColumn.value = data.formTemplateFieldVOList
  code.value = data.code
  tableMoreDialogRef.value.showDraw()
}
</script>
<style lang="scss" scoped>
.totalTable {
  width: 100%;
  text-align: right;
  // margin-top: -25px;
  span {
    color: var(--el-color-primary);
  }
}
.more {
  float: right;
  font-size: 14px;
  line-height: 28px;
  margin-top: -28px;
}
</style>
